package cn.jiguang.jgssp.adapter.gdt;

import android.content.Context;

import com.qq.e.comm.managers.GDTAdSdk;
import com.qq.e.comm.managers.setting.GlobalSetting;

import java.util.HashMap;
import java.util.Map;

import cn.jiguang.jgssp.ADJgSdk;
import cn.jiguang.jgssp.ad.adapter.ADBaseIniter;
import cn.jiguang.jgssp.config.ADJgInitConfig;
import cn.jiguang.jgssp.util.ADJgLogUtil;

/**
 * @author ciba
 * @description 头条平台初始化类
 * @date 2020/3/25
 */
public class ADSuyiIniter extends ADBaseIniter {
    @Override
    public void init(Context context, String appId, String appKey, ADJgInitConfig config) {
        // 设置广点通是否支持隐私政策
        GlobalSetting.setAgreePrivacyStrategy(config == null || config.isAgreePrivacyStrategy());
        // 是否可使用设备id
        GlobalSetting.setAgreeReadDeviceId(config == null || config.isCanUsePhoneState());
        // 是否可使用安卓id
        GlobalSetting.setAgreeReadAndroidId(config == null || config.isCanUsePhoneState());
        // 是否允许读取安装列表
        GlobalSetting.setEnableCollectAppInstallStatus(config == null || config.isCanReadInstallList());

        Map<String, Boolean> params = new HashMap();
        // 优量汇SDK将不采集mac地址
        params.put("mac_address", config == null || config.isCanUseWifiState());
        params.put("bssid", config == null || config.isCanUseWifiState());
        params.put("ssid", config == null || config.isCanUseWifiState());
        // 允许优量汇SDK采集android_id
        params.put("android_id", config == null || config.isCanUsePhoneState());
        // 不设置device_id默认为允许
        params.put("device_id", config == null || config.isCanUsePhoneState());
        // 目前只会获取粗略地理位置信息，禁止读取经纬度坐标
        params.put("cell_id", config == null || config.isCanUseLocation());
        GlobalSetting.setAgreeReadPrivacyInfo(params);

        Map convOptimizeInfoParams = new HashMap();
        convOptimizeInfoParams.put("hieib", false);
        GlobalSetting.setConvOptimizeInfo(convOptimizeInfoParams);

        // 广点通广告SDK初始化
        GDTAdSdk.initWithoutStart(ADJgSdk.getInstance().getContext(), appId);
        GDTAdSdk.start(new GDTAdSdk.OnStartListener() {
            @Override
            public void onStartSuccess() {
                ADJgLogUtil.d("gdtadapter init success");
            }

            @Override
            public void onStartFailed(Exception e) {
                ADJgLogUtil.d("gdtadapter init fail msg: " + e.toString());
                callInitFailed();
            }
        });
        callInitSuccess();
    }

    @Override
    public String getAdapterVersion() {
        return "4.603.1473.10151";
    }

    @Override
    public void setPersonalizedAdEnabled(boolean personalizedAdEnabled) {
        GlobalSetting.setPersonalizedState(personalizedAdEnabled ? 0 : 1);
    }

    @Override
    public boolean isClientBid() {
        return true;
    }

    @Override
    public boolean isParallelLoad() {
        return true;
    }
}
